﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;

using ProjectBase.Core;

using $prjsn$.Common.Data.Services;
using $prjsn$.Entity.Services;

namespace $safeprojectname$.Services
{
    public class TranslatorFilterValidator : FilterValidatorBase<Translator, TranslatorFilter, int>
    {
        protected override void Init(RuleCollection<TranslatorFilter> rules) 
        { 
            base.Init(rules);
            rules.Remove("OrderBy");
        }
    }
    public class TranslatorValidator : EntityValidatorBase<Translator, int, ITranslatorDao>
    {
        protected override void Init(RuleCollection<Translator> rules)
        {
            // unique key and area
            rules.For(entity => entity.Area).RequireLengthBetween(0, 150)
                .AsRequired()
                .BreakOnError();
            rules.For(entity => entity.Key).RequireLengthBetween(1, 300)
                .BreakOnError();

            rules.IsUnique(entity => Dao.Find(entity.ID, new TranslatorFilter
            {
                KeySearch = entity.Key,
                AreaSearch = entity.Area
            }), "Key", "Area");
        }
    }
}